In the domain of computer languages that support query operations, there have traditionally been two distinct approaches. According to one approach query comprehensions can be employed and according the an alternative approach method calls to an Application Programming Interface (API) can be utilized. One of the benefits of calling an API directly is that an associated query expression can be more composable in the sense that a user can piece together query clauses and/or small independent queries into larger queries. Unfortunately, one difficulty with using the underlying API in conventional frameworks is that users of this approach are forced to pass in delegates and/or lambda expressions in order to introduce new variables in scope.
In contrast conventional languages with query support that employ comprehensions or query expressions is that the comprehensions can be utilized to introduce a scope for control variables that can potentially span over several clauses of the query. While this can provide for an advantage over using API calls, there exist associated disadvantages to this approach as well. For example, in many languages that support query comprehensions such as Structure Query Language (SQL), XQuery, Haskell, etc., the comprehensions ubiquitously exist as monolithic constructs. Thus, the comprehensions are inherently less composable, and users cannot, e.g., arbitrarily stitch together larger queries from smaller ones
Standard varieties of SQL represent primary examples of non-compositional languages that impose many restrictions on how and where queries can be nested inside other queries and how queries can be stacked together. The basic syntax of an SQL query is: Select, From, Where, Groupby, Having, OrderBy, from which the user is largely restricted from introducing additional query operators and/or in different orders. These and other monolithic constructs allow for very little flexibility in, for instance, placing another From clause after the Where clause, or when nesting queries inside the Select clause. Another example is XQuery that utilizes the For, Let, Where, Order By, Return (FLWOR), which suffers from similar shortcomings.